package com.achievement.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.achievement.domain.dto.honor.ReviewStandardDTO;
import com.achievement.domain.entity.ReviewStandardEntity;
import com.achievement.domain.param.honor.ReviewStandardParam;
import com.achievement.domain.vo.honor.ReviewStandardVO;
import com.achievement.mapper.ReviewStandardMapper;
import com.achievement.mappings.ReviewStandardMapping;
import com.achievement.service.IReviewStandardService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ReviewStandardServiceImpl extends ServiceImpl<ReviewStandardMapper, ReviewStandardEntity> implements IReviewStandardService {
    @Autowired
    private ReviewStandardMapping mapping;

    @Override
    public List<ReviewStandardVO> selectByPage(ReviewStandardParam param) {
        LambdaQueryWrapper<ReviewStandardEntity> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(StringUtils.isNotEmpty(param.getReviewSchemeId()), ReviewStandardEntity::getReviewSchemeId, param.getReviewSchemeId());
        List<ReviewStandardVO> voList = this.baseMapper.selectByPage(queryWrapper);
        return voList;
    }
    @Override
    public List<ReviewStandardEntity> getListByConditions(ReviewStandardDTO patentDTO) {
        QueryWrapper<ReviewStandardEntity> queryWrapper = new QueryWrapper();
        List<ReviewStandardEntity> list = this.list(queryWrapper);
        return list;
    }
    @Override
    public List<ReviewStandardVO> getListByReviewSchemeId(String reviewSchemeId) {
        LambdaQueryWrapper<ReviewStandardEntity> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(StringUtils.isNotEmpty(reviewSchemeId),ReviewStandardEntity::getReviewSchemeId,reviewSchemeId);
        List<ReviewStandardVO> list = this.list(queryWrapper).stream().map(mapping::entity2Vo).collect(Collectors.toList());
        return list;
    }
    @Override
    public ReviewStandardVO getInfoById(String id) {
        ReviewStandardEntity entity = this.getById(id);
        ReviewStandardVO ReviewStandardVO=mapping.entity2Vo(entity);
        return ReviewStandardVO;
    }

    @Override
    public boolean add(ReviewStandardDTO dto) {
        ReviewStandardEntity entity = mapping.dto2Entity(dto);
        return this.save(entity);
    }


    @Override
    public boolean update(ReviewStandardDTO dto) {
        ReviewStandardEntity entity = mapping.dto2Entity(dto);
        return this.updateById(entity);
    }

    @Override
    public boolean batchRemove(List<String> ids) {
        boolean returnResult=false;
        returnResult=this.removeByIds(ids);
        return returnResult;
    }
    @Override
    public boolean bitchAdd(List<ReviewStandardDTO> reviewStandardDTOs, String reviewSchemeId){
        List<ReviewStandardEntity> entityList = reviewStandardDTOs.stream().map(mapping::dto2Entity).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(entityList)){
            entityList.forEach(a->{
                //a.setId(UUID.randomUUID().toString().replace("-",""));
                a.setReviewSchemeId(reviewSchemeId);
            });
            return this.saveBatch(entityList);
        }
        return  true;
    }
    @Override
    public boolean deleteReviewStandardByReviewSchemeId(String reviewSchemeId){
        LambdaQueryWrapper<ReviewStandardEntity> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(ReviewStandardEntity::getReviewSchemeId, reviewSchemeId);
        return this.remove(queryWrapper);
    }
}
